<!-- 任务单详情弹窗 -->
<template>
  <el-drawer v-model="drawerVisible" :destroy-on-close="true" size="600px" :title="`${drawerProps.title}`">
    <el-space direction="vertical">
      <el-descriptions :column="2" title="供应商信息" border>
        <el-descriptions-item width="400" label="商品id" :span="2">{{ drawerProps.row!.goodsId }}</el-descriptions-item>
        <el-descriptions-item width="400" label="商品名称" :span="2">{{ drawerProps.row!.goodsName }}</el-descriptions-item>
        <el-descriptions-item width="400" label="商品型号" :span="2">{{ drawerProps.row!.goodsModel }}</el-descriptions-item>
        <el-descriptions-item width="400" label="一级分类" :span="2">{{ listName }}</el-descriptions-item>
        <el-descriptions-item width="400" label="二级分类" :span="2">{{ setName }}</el-descriptions-item>
        <el-descriptions-item width="400" label="商品原价">{{ drawerProps.row!.goodsPrice }}</el-descriptions-item>
        <el-descriptions-item width="400" label="计量单位">{{ drawerProps.row!.measureUnit }}</el-descriptions-item>
        <el-descriptions-item width="400" label="商品成本">{{ drawerProps.row!.goodsCost }}</el-descriptions-item>
        <el-descriptions-item width="400" label="商品折扣">{{ drawerProps.row!.goodsDiscount }}</el-descriptions-item>
        <el-descriptions-item width="400" label="供应商id" :span="2">{{
          drawerProps.row!.vendorInfo!.vendorId
        }}</el-descriptions-item>
        <el-descriptions-item width="400" label="供应商名称" :span="2">{{
          drawerProps.row!.vendorInfo!.vendorName
        }}</el-descriptions-item>
        <el-descriptions-item width="400" label="商品保质期限" :span="2">{{
          drawerProps.row!.goodsShelfLife
        }}</el-descriptions-item>
        <el-descriptions-item width="400" label="可否退货" :span="2">
          <el-tag v-if="drawerProps.row!.optReturn === 0" type="danger">否</el-tag>
          <el-tag v-if="drawerProps.row!.optReturn === 1" type="success">是</el-tag>
        </el-descriptions-item>
        <el-descriptions-item width="400" label="可否换货" :span="2">
          <el-tag v-if="drawerProps.row!.optReplace === 0" type="danger">否</el-tag>
          <el-tag v-if="drawerProps.row!.optReplace === 1" type="success">是</el-tag>
        </el-descriptions-item>
        <el-descriptions-item width="400" label="商品备注信息" :span="2">{{ drawerProps.row!.goodsRemark }}</el-descriptions-item>
      </el-descriptions>
    </el-space>
    <el-form
      ref="ruleFormRef"
      label-width="100px"
      label-suffix=" :"
      :rules="rules"
      :disabled="drawerProps.isView"
      :model="drawerProps.row"
      :hide-required-asterisk="drawerProps.isView"
    >
    </el-form>
    <template #footer>
      <el-button @click="drawerVisible = false">关闭</el-button>
    </template>
  </el-drawer>
</template>

<script setup lang="ts" name="DetailDrawer">
import { Good } from "@/api/interface";
import { getClassifyBySetId } from "@/api/modules/good";
import { ref, reactive } from "vue";
// import { getUserInfo } from "@/api/modules/user";

const rules = reactive({});

interface DrawerProps {
  title: string;
  isView: boolean;
  row: Partial<Good.ReqGoodsEntity>;
  courierName?: String;
  api?: (params: any) => Promise<any>;
  getTableList?: () => void;
}

const drawerVisible = ref(false);
const drawerProps = ref<DrawerProps>({
  isView: false,
  title: "",
  row: {}
});

const listName = ref("");
const setName = ref("");

// 接收父组件传过来的参数
const acceptParams = async (params: DrawerProps) => {
  drawerProps.value = params;
  if (drawerProps.value.row!.setId) {
    const result = await getClassifyBySetId({ setId: drawerProps.value.row!.setId });
    listName.value = result.data.listName; // 将返回的分类名称赋给 categoryNam
    setName.value = result.data.setName;
  }
  drawerVisible.value = true;
};

defineExpose({
  acceptParams
});
</script>
